﻿using System;
using System.Reflection;
using NHibernate;
using NHibernate.Cfg;
using NHibernate.Mapping;

namespace Romantics.Domain.Objects
{
    public class SessionFactory
    {
        private static ISessionFactory sessionFactory;
        static readonly object factorylock = new object();

        public static ISessionFactory Factory
        {
            get
            {
                lock (factorylock)
                {
                    if (sessionFactory == null)
                    {
                        sessionFactory = new Configuration()
                            .Configure()
                            .AddAssembly(typeof(Entity).Assembly)
                            .BuildSessionFactory();
                    }
                }
                return sessionFactory;
            }
        }
    }
}
